package com.guaju.yueshangclothing.viewmodel;

import android.content.Context;
import android.databinding.BaseObservable;
import android.databinding.Bindable;
import android.databinding.BindingAdapter;
import android.view.View;
import android.widget.LinearLayout;

import com.guaju.yueshangclothing.BR;
import com.guaju.yueshangclothing.dao.SearchHistoryModel;
import com.guaju.yueshangclothing.widget.FlowLayout;
import com.guaju.yueshangclothing.widget.SearchHistoryItem;

import java.util.ArrayList;

/**
 * Created by guaju on 2018/9/12.
 */

public class SearchHistoryMV extends BaseObservable {
    public static Context context;
    //    public String str;
    public ArrayList<SearchHistoryModel> lists;


    @Bindable
    public ArrayList<SearchHistoryModel> getLists() {
        return lists;
    }

    public void setLists(ArrayList<SearchHistoryModel> lists) {
        this.lists = lists;
        notifyPropertyChanged(BR.lists);
    }

    public SearchHistoryMV(Context context, ArrayList<SearchHistoryModel> lists) {
        this.lists = lists;
        this.context = context;

    }

    @BindingAdapter("bind:history")
    public static void setHistory(FlowLayout layout, ArrayList<SearchHistoryModel> lists) {
        if (lists == null || lists.size() == 0) {
            layout.setVisibility(View.GONE);
            return;
        }
        layout.setVisibility(View.VISIBLE);
        for (SearchHistoryModel s : lists) {
            SearchHistoryItem searchHistoryItem = new SearchHistoryItem(context);
            searchHistoryItem.settext(s.getHistory());
            layout.addView(searchHistoryItem);
        }
    }

    @BindingAdapter("bind:show")
    public static void show(LinearLayout layout, ArrayList<SearchHistoryModel> lists){
        if (lists == null || lists.size() == 0) {
            layout.setVisibility(View.VISIBLE);
        }else{
            layout.setVisibility(View.INVISIBLE);
        }
    }


}
